/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package shmallarchitect.web.pages;

import java.util.Map;
import javax.faces.context.FacesContext;
import javax.faces.el.ValueBinding;

/**
 *
 * @author jaccus
 */
public class JSFUtil {



  public static ValueBinding getValueBinding(String expression)
  {
    FacesContext context = FacesContext.getCurrentInstance();
    return context.getApplication().createValueBinding(expression);
  }

  public static String getValueBindingString(String expression)
  {
    FacesContext context = FacesContext.getCurrentInstance();
    ValueBinding currentBinding =  context.getApplication().createValueBinding(expression);
    return (String) currentBinding.getValue(context);

  }


    public static Object getManagedObject(String objectName)
  {
    FacesContext context = FacesContext.getCurrentInstance();
    Object requestedObject =  context.getApplication().getVariableResolver().resolveVariable(context, objectName);
    //TODO: ELresolver + getuserbycredentials etc
    return  requestedObject;
  }


  public static void storeOnSession(FacesContext ctx, String key, Object object) {
      Map sessionState = ctx.getExternalContext().getSessionMap();
      sessionState.put(key, object);
  }
}
